package cn.edu.suda.catalina.util;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cn.edu.suda.catalina.entity.Diary;
import cn.edu.suda.catalina.health.AnotherFragment;
import cn.edu.suda.catalina.health.DiaryShowFragment;
import cn.edu.suda.catalina.health.R;

/**
 * Created by gzy on 2016/6/21.
 */

public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyViewHolder> {

    private List<Diary> mValues;
    private AnotherFragment.OnAnotherFragmentInteractionListener mListener;

    public MyRecyclerViewAdapter(List<Diary> mValues, AnotherFragment.OnAnotherFragmentInteractionListener mListener) {
        this.mValues = mValues;
        this.mListener = mListener;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_another_item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, int position) {

        holder.mDiary = mValues.get(position);
        holder.timeText.setText(mValues.get(position).getTime());
        holder.diaryText.setText(mValues.get(position).getDiary());

        holder.mView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onAnotherFragmentInteraction(holder.mDiary);
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return mValues.size();
    }
}
